//-----------------------------------------------------------------------------
// Copyright 2015 Ihor Nehrutsa
//
// This file is part of LDmicro.
//
// LDmicro is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// LDmicro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with LDmicro.  If not, see <http://www.gnu.org/licenses/>.
//-----------------------------------------------------------------------------
#include "stdafx.h"

// clang-format off

//---------------------------------------------------------------------------
/* 7 segments display

     a
    --
 f|    |b
  |  g |
    --
 e|    |c
  |    |
    --
     d  DP

SEGMENT   DP g f e d c b a
BIT        7 6 5 4 3 2 1 0
nibbles   ^       ^       ^
*/
int32_t char7seg[] = { // unsigned char in fact, but we need a int32_t
//ASCII characters from 0x00 to 0x7F
//     0    1    2    3    4    5    6    7    8    9    A    b    C    d    E    F
    0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,
//     0.   1.   2.   3.   4.   5.   6.   7.   8.   9.   A.   b.   C.   d.   E.   F.
    0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0xF7,0xFC,0xB9,0xDE,0xF9,0xF1,
// space    !    "    #    $    %    &    '    (    )    *    +    ,    -    .    /
    0x00,0xB0,0x22,0x4E,0x6D,0xD2,0xDA,0x20,0x39,0x0F,0x72,0x70,0x0C,0x40,0x80,0x52,
//     0    1    2    3    4    5    6    7    8    9    :    ;    <    =    >    ?
    0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x09,0x0D,0x61,0x41,0x43,0xD3,
//     @    A    b    C    d    E    F    G    h    I    J    K    L    M    n    o
    0x9F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x3D,0x74,0x30,0x1E,0x75,0x38,0x55,0x54,0x5C,
//     P    q    R    S    t    U    v    W    X    Y    Z    [    \    ]    ^    _
    0x73,0x67,0x33,0x6D,0x78,0x3E,0x1C,0x6A,0x76,0x6E,0x5B,0x39,0x64,0x0F,0x23,0x08,
//     `    a    b    c    d    e    F    g    h    i    j    k    l    m    n    o
    0x20,0x5F,0x7C,0x58,0x5E,0x7B,0x71,0x6F,0x74,0x10,0x0E,0x75,0x18,0x55,0x54,0x5C,
//     p    q    r    S    t    U    v    w    X    Y    Z    {    |    }    ~    
    0x73,0x67,0x50,0x6D,0x78,0x3E,0x1C,0x6A,0x76,0x6E,0x5B,0x39,0x30,0x0F,0x01,0x00,
//Special cases characters
// degree
    0x63
};
#define LEN7SEG_ (sizeof(char7seg) / sizeof(char7seg[0]))
//---------------------------------------------------------------------------
/* 9 segments display

     a
    ---j
 f|   / |b
  |  /  |
    ---g
 e|  /  |c
  | /   |
   m---
     d   DP

SEGMENT   0 0 m j DP g f e d c b a 
BIT           9 8  7 6 5 4 3 2 1 0
nibbles  ^        ^       ^       ^
*/
int32_t char9seg[] = { 
//ASCII characters from 0x00 to 0x7F
//       0      1      2      3      4      5      6      7      8      9      A      B      C      d      E      F
    0x033F,0x0106,0x005B,0x004F,0x0066,0x006D,0x007D,0x0007,0x007F,0x006F,0x0077,0x017D,0x0039,0x005E,0x0079,0x0071,
//       0.     1.     2.     3.     4.     5.     6.     7.     8.     9.     A.     B.     C.     d.     E.     F.
    0x03BF,0x0186,0x00DB,0x00CF,0x00E6,0x00ED,0x00FD,0x0087,0x00FF,0x00EF,0x00F7,0x01FD,0x00B9,0x00DE,0x00F9,0x00F1,
//   space      !      "      #      $      %      &      '      (      )      *      +      ,      -      .      /
    0x0000,0x00B0,0x0120,0x404E,0x006D,0x00D2,0x00DA,0x0100,0x0039,0x000F,0x0072,0x0340,0x0200,0x0040,0x0080,0x0300,
//       0      1      2      3      4      5      6      7      8      9      :      ;      <      =      >      ?
    0x033F,0x0106,0x005B,0x004F,0x0066,0x006D,0x007D,0x0007,0x007F,0x006F,0x0009,0x0201,0x0061,0x0041,0x0043,0x00D3,
//       @      A      B      C      d      E      F      G      h      I      J      K      L      M      n      O
    0x009F,0x0077,0x017D,0x0039,0x005E,0x0079,0x0071,0x003D,0x0074,0x0030,0x001E,0x0075,0x0038,0x0055,0x0054,0x003F,
//       P      q      R      S      t      U      V      W      X      Y      Z      [      \      ]      ^      _
    0x0073,0x0067,0x0033,0x006D,0x0078,0x003E,0x0330,0x006A,0x4364,0x006E,0x4349,0x0039,0x0064,0x000F,0x0102,0x0008,
//       `      a      b      c      d      e      f      g      h      i      j      k      l      m      n      o
    0x0020,0x005F,0x007C,0x0058,0x005E,0x007B,0x0171,0x006F,0x0074,0x0010,0x000E,0x0075,0x0018,0x0055,0x0054,0x005C,
//       p      q      r      S      t      U      v      w      X      Y      Z      {      |      }      ~      
    0x0073,0x0067,0x0050,0x006D,0x0078,0x003E,0x0210,0x006A,0x4364,0x006E,0x0309,0x0039,0x0030,0x000F,0x0001,0x0000,
//Special cases characters
//  degree
    0x0063
};
#define LEN9SEG_ (sizeof(char9seg) / sizeof(char9seg[0]))
//---------------------------------------------------------------------------
/* 14 segments display

     a
  h --- j
 f|\ |i/|b
  | \|/ |
 g1-- --g2
 e| /|\ |c
  |/ |l\|
  m --- k
     d   DP

SEGMENT  0 g2  l  k  i  h  m  j DP g1  f  e  d  c  b  a
BIT        14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
nibbles ^          ^           ^           ^           ^
*/
int32_t char14seg[] = {
//ASCII characters from 0x00 to 0x7F
//       0      1      2      3      4      5      6      7      8      9      A      B      C      D      E      F
    0x033F,0x0106,0x405B,0x404F,0x4066,0x406D,0x407D,0x0007,0x407F,0x406F,0x4077,0x680F,0x0039,0x280F,0x0079,0x0071,
//       0.     1.     2.     3.     4.     5.     6.     7.     8.     9.     A.     B.     C.     D.     E.     F.
    0x03BF,0x0186,0x40DB,0x40CF,0x40E6,0x40ED,0x40FD,0x0087,0x40FF,0x40EF,0x40F7,0x688F,0x00B9,0x288F,0x00F9,0x00F1,
//   space      !      "      #      $      %      &      '      (      )      *      +      ,      -      .      /
    0x0000,0x2880,0x0820,0x684E,0x686D,0x5764,0x5459,0x0100,0x1100,0x0600,0x7f40,0x6840,0x0200,0x4040,0x0080,0x0300,
//       0      1      2      3      4      5      6      7      8      9      :      ;      <      =      >      ?
    0x033F,0x0106,0x405B,0x404F,0x4066,0x406D,0x407D,0x0007,0x407F,0x406F,0x0009,0x0201,0x4061,0x4041,0x4043,0x6083,
//       @      A      B      C      D      E      F      G      H      I      J      K      L      M      N      O
    0x205F,0x4077,0x417D,0x0039,0x280F,0x0079,0x0071,0x403D,0x4076,0x2809,0x001E,0x1170,0x0038,0x0536,0x1436,0x003F,
//       P      Q      R      S      T      U      V      W      X      Y      Z      [      \      ]      ^      _
    0x4073,0x103F,0x5073,0x406D,0x2801,0x003E,0x0330,0x1236,0x1700,0x2500,0x4349,0x0039,0x1400,0x000F,0x0102,0x0008,
//       `      a      b      c      d      e      f      g      h      i      j      k      l      m      n      o
    0x0400,0xA058,0x1078,0x4058,0x420E,0x0258,0x4171,0x440F,0x4074,0x0010,0x000E,0x5070,0x0018,0x6054,0x1050,0x405C,
//       p      q      r      s      t      u      v      w      x      y      z      {      |      }      ~      
    0x0171,0x4407,0x4050,0x5008,0x0078,0x001C,0x0210,0x1214,0x5240,0x440E,0x0248,0x1140,0x2800,0x4600,0x0001,0x0000,
//Special cases characters
//  degree
    0x0063
};
#define LEN14SEG_ (sizeof(char14seg) / sizeof(char14seg[0]))
//---------------------------------------------------------------------------
/* 16 segments display

   a1 a2
  h-- --j
 f|\ |i/|b
  | \|/ |
 g1-- --g2
 e| /|\ |c
  |/ |l\|
  m-- --k
   d1 d2 DP

SEGMENT   0  0  0 a2 d2 g2  l  k  i  h  m  j DP g1  f  e d1  c  b a1
BIT               16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
nibbles  ^          ^           ^           ^           ^           ^
*/
int32_t char16seg[] = {
//ASCII characters from 0x00 to 0x7F
//        0       1       2       3       4       5       6       7       8       9       A       B       C       D       E       F
    0x1833F,0x00106,0x1C05B,0x1C04F,0x04066,0x1C06D,0x1C07D,0x10007,0x1C07F,0x1C06F,0x04077,0x0680F,0x00039,0x0280F,0x00079,0x00071,
//        0.      1.      2.      3.      4.      5.      6.      7.      8.      9.      A.      B.      C.      D.      E.      F.
    0x183BF,0x00186,0x1C0DB,0x1C0CF,0x040E6,0x1C0ED,0x1C0FD,0x10087,0x1C0FF,0x1C0EF,0x040F7,0x0688F,0x000B9,0x0288F,0x000F9,0x000F1,
//   s pace       !       "       #       $       %       &       '       (       )       *       +       ,       -       .       /
    0x00000,0x02880,0x00820,0x0E84E,0x1E86D,0x05764,0x1D459,0x00100,0x01100,0x00600,0x07f40,0x06840,0x00200,0x04040,0x00080,0x00300,
//        0       1       2       3       4       5       6       7       8       9       :       ;       <       =       >       ?
    0x1833F,0x00106,0x1C05B,0x1C04F,0x04066,0x1C06D,0x1C07D,0x10007,0x1C07F,0x1C06F,0x00009,0x00201,0x14061,0x14041,0x14043,0x16083,
//        @       A       B       C       D       E       F       G       H       I       J       K       L       M       N       O
    0x1A05F,0x14077,0x1C17D,0x18039,0x1A80F,0x18079,0x10071,0x1C03D,0x04076,0x1A809,0x0801E,0x01170,0x08038,0x00536,0x01436,0x1803F,
//        P       Q       R       S       T       U       V       W       X       Y       Z       [       \       ]       ^       _
    0x14073,0x1903F,0x15073,0x1C06D,0x12801,0x0803E,0x00330,0x01236,0x01700,0x02500,0x1C349,0x1A800,0x01400,0x02809,0x00102,0x08008,
//        `       a       b       c       d       e       f       g       h       i       j       k       l       m       n       o
    0x00400,0x0A058,0x09078,0x0C058,0x0C20E,0x08258,0x16840,0x1C40F,0x04074,0x00010,0x0A006,0x05070,0x08018,0x06054,0x01050,0x0C05C,
//        p       q       r       s       t       u       v       w       x       y       z       {       |       }       ~       
    0x10171,0x14407,0x04050,0x0D008,0x0E840,0x0801C,0x00210,0x01214,0x05240,0x0C40E,0x08248,0x1A840,0x02800,0x06809,0x10001,0x00000,
//Special cases characters
//  degree
    0x0063
};
#define LEN16SEG_ (sizeof(char16seg) / sizeof(char16seg[0]))
//---------------------------------------------------------------------------

// clang-format on
